///Log handler object
//
//Copyright (c) Embedded Systems Technologies All Rights Reserved
//
/*******************************************************************************
 * Author     : Mike Glavin
 * Description:
 *******************************************************************************/
#ifndef Clog_H_
#define Clog_H_

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <iostream>
#include <string.h>
#include <vector>
#ifdef linux
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <syslog.h>
#else
#include <winsock2.h>
#include <ws2tcpip.h>
#include <windows.h>
#include <tchar.h>
#include <time.h>
#endif // linux

using namespace std;

class CLog {
 public:
	CLog(char *ObjectName);
	~CLog();

    void initLogger(bool isAppending);
	void log_start(char *stat_description);
	void log_stop(char *stat_description);
	void log_insert(char *generic_message);
	void cr();

    char msg_buff[8192];
 private:

    double calculateAverageTime(char *stat_description, double elapsed_time, int *avgCount);
    bool registerMetric(string stat_description, double elapsed_time);
    double updateAverageBuffers(int metric_index, double elapsed_time, int *avgCount);

#ifdef linux
	void process_stats(char *stat_description, struct timespec *tp_start, struct timespec *tp_end);

	clockid_t clk_id;
	struct timespec tp_start, tp_end, tp_start_reset;
#else
	void process_stats(char *stat_description);
	char *get_date_and_time();

    string parentName;
    FILE *fp_out;
    double PCFreq, total_time;
    __int64 CounterStart, CounterEnd;
    LARGE_INTEGER li_start, li_end, li;
    bool bQueryPerformanceFrequency;
#endif

    vector<string> vAvgTagNames;
    vector<double> dAvgTime;
    vector<int> iAvgCounter;
};

#endif /*Clog_H_*/
